package com.tarena.baking.response;

import lombok.Data;

@Data
public class JsonResult {
    /**
     * 操作结果的状态码（状态标识）
     */
    private Integer code;
    /**
     * 操作失败时的提示文本
     */
    private String msg;
    /**
     * 操作成功时响应的数据
     */
    private Object data;

    public static JsonResult ok() {
        return ok(null);
    }

    public static  JsonResult ok(Object data) {
        JsonResult  jsonResult = new JsonResult();
        jsonResult.code = StatusCode.OK.getValue();
        jsonResult.data = data;
        return jsonResult;
    }


    public static JsonResult fail(StatusCode serviceCode, String message) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.code = serviceCode.getValue();
        jsonResult.msg = message;
        return jsonResult;
    }
}
